import http from '../../utils/http';
import * as types from "../mutations-type";
import md5 from "js-md5"

const state = {};

const actions = {
    //检测会员信息
    [types.INVEST_CHECKUSER]({}, form) {
        return new Promise((resolve) => {
            http.post('/user/checkUser', form).then((res) => {
                return resolve(res.data);
            });
        });
    },

    //注册投资会员
    [types.INVEST_REGISTER]({ dispatch }, form) {
        form.pwd2 = md5(form.pwd2)
        form.amount = form.amount * 100
        return new Promise((resolve) => {
            http.post('/user/invest.register', form).then((res) => {
                if (res.data.code == 0) dispatch(types.USER_INFO)
                return resolve(res.data);
            });
        });
    },

    //注册合伙人
    [types.INVEST_AGENCY]({}, form) {
        return new Promise((resolve) => {
            http.post('/user/invest.proxy.register', form).then((res) => {
                return resolve(res.data);
            });
        });
    },

    //股权投资
    [types.INVEST_STOCK]({}, form) {
        return new Promise((resolve) => {
            http.post('/user/invest', form).then((res) => {
                return resolve(res.data);
            });
        });
    },

    //股权投资列表
    [types.INVEST_STOCK_LIST]({ dispatch }, form) {
        return new Promise((resolve) => {
            http.post('/user/invest.lists', form).then((res) => {
                if (res.data.code == 0) dispatch(types.USER_INFO)
                return resolve(res.data);
            });
        });
    },

    //购物积分明细
    [types.SHOP_POINT_LIST]({}, form) {
        return new Promise((resolve) => {
            http.post('/user/point.shop.lists', form).then((res) => {
                return resolve(res.data);
            });
        });
    },

    //增值积分明细
    [types.BONUS_POINT_LIST]({}, form) {
        return new Promise((resolve) => {
            http.post('/user/point.bonus.lists', form).then((res) => {
                return resolve(res.data);
            });
        });
    },
    //增值积分提现
    [types.CASH_POINT]({ dispatch }, form) {
        return new Promise((resolve) => {
            http.post('/user/cash.apply', form).then((res) => {
                console.log(res)
                if (res.data.code == 0) dispatch(types.USER_INFO)
                return resolve(res.data);
            });
        });
    },
    //增值积分转账
    [types.INVEST_TRANSFER]({ dispatch }, form) {
        return new Promise((resolve) => {
            http.post('/user/transfer', form).then((res) => {
                console.log(res)
                if (res.data.code == 0) dispatch(types.USER_INFO)
                return resolve(res.data);
            });
        });
    },

    //提现明细
    [types.CASH_LIST]({}, form) {
        return new Promise((resolve) => {
            http.post('/user/cash.lists', form).then((res) => {
                return resolve(res.data);
            });
        });
    },
    //销售明细
    [types.SALE_LIST]({}, form) {
        return new Promise((resolve) => {
            http.post('/user/point.detail', form).then((res) => {
                return resolve(res.data);
            });
        });
    },

    //取消提现申请
    [types.CASH_CANCEL]({ dispatch }, form) {
        return new Promise((resolve) => {
            http.post('/user/cash.cancel', form).then((res) => {
                dispatch(types.USER_INFO)
                return resolve(res.data);
            });
        });
    },


    //获取团队信息
    [types.TERM_INFO]({}, form) {
        return new Promise((resolve) => {
            http.post('/user/getTeam', form).then((res) => {
                return resolve(res.data);
            });
        });
    },
    //获取合伙人列表
    [types.TEAM_LIST]({}, form) {
        return new Promise((resolve) => {
            http.post('/user/getMallTeam', form).then((res) => {
                return resolve(res.data);
            });
        });
    },

    //冻结信息
    [types.FROZEN_INFO]({}) {
        return new Promise((resolve) => {
            http.post('/user/frozen.info').then((res) => {
                return resolve(res.data);
            });
        });
    },
    //充值
    [types.RECHARGE]({}) {
        return new Promise((resolve) => {
            http.post('/user/recharge').then((res) => {
                return resolve(res.data);
            });
        });
    },



};

const mutations = {};
export default {
    state,
    actions,
    mutations,
    getters: {}
}